Bash Copy Directory and File One liner

I needed a #bash shell script that automatically copied over private files such as .env and home.tsx within my web development stack

Here is the stack overflow post by Mark Amery that helped

mkdir -p /foo/bar && cp myfile.txt $_

$_ - expands to the last argument to the previous command

if the path as spaces, the strings need to be wrapped in quotes

mkdir -p "/my directory/name with/spaces" && cp "my filename with spaces.txt" "$_"

if you want to name the file with a new name

mkdir -p /foo/bar && cp ../from/another/dir/myfile.txt $_/my-file-with-new-name